﻿using WXWorkSvc.Common.Data;

namespace OpenPms.Controllers;
/// <summary>
/// /*
/// Swagger出错原因：
/// 1.没有http get或者post属性
/// 2.get或者post的属性的名称重复
/// 3.数据类名称重复，比如两个类都包含了data的类
/// </summary>
/// <typeparam name="T"></typeparam>
#if !DEBUG
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
#endif
[ApiController]
//[ApiExplorerSettings(IgnoreApi =true)]
[Produces("application/json")]
public class PmsControllerBase<T> : ControllerBase
{
    #region Claim Para
#if DEBUG
    protected int HotelId = 10000;
#else
    protected int HotelId=>User.GetExtId();
#endif
    #endregion


    private readonly IServiceProvider serviceProvider;
    private OrderService? _OrderService;
    protected OrderService OrderService
    {
        get
        {
            if (_OrderService == null)
                _OrderService = serviceProvider.GetRequiredService<OrderService>();
            return _OrderService;
        }
    }
    private WXDbContext? _WXDb;
    protected WXDbContext wxdb
    {
        get
        {
            if (_WXDb == null)
                _WXDb = serviceProvider.GetRequiredService<WXDbContext>();
            return _WXDb;
        }
    }
    protected AppDbContext? _db;
    protected AppDbContext db
    {
        get
        {
            if (_db == null)
                _db = serviceProvider.GetRequiredService<AppDbContext>();
            return _db;
        }
    }
    private ILogger<T>? _logger;
    protected ILogger<T> logger
    {
        get
        {
            if (_logger == null)
                _logger = serviceProvider.GetRequiredService<ILogger<T>>();
            return _logger;
        }
    }
    private IConfiguration? _configuration;
    protected IConfiguration configuration
    {
        get
        {
            if (_configuration == null)
                _configuration = serviceProvider.GetRequiredService<IConfiguration>();
            return _configuration!;
        }
    }
    protected PmsControllerBase(IServiceProvider serviceProvider)
    {
        this.serviceProvider = serviceProvider;
    }
}
